<template>
  <div class="page">
    <el-form :inline="true">
      <el-form-item>
        <el-select v-model="query.type">
          <el-option
            label="车房券提现审核中"
            value="车房券提现审核中"
          ></el-option>
          <el-option label="车房券提现成功" value="车房券提现成功"></el-option>
          <el-option label="车房券提现失败" value="车房券提现失败"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handlePageChange(1)">查询</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="list" border>
      <el-table-column type="index" label="序号"></el-table-column>
      <el-table-column prop="id" label="ID"></el-table-column>
      <el-table-column prop="detailed" label="描述"></el-table-column>
      <el-table-column prop="name" label="用户账号"></el-table-column>
      <el-table-column prop="balance" label="余额"></el-table-column>
      <el-table-column prop="amount" label="金额"></el-table-column>
      <el-table-column prop="inOut" label="支出/收入"></el-table-column>
      <el-table-column prop="remark" label="备注"></el-table-column>
      <el-table-column prop="createTime" label="提现时间"></el-table-column>
      <el-table-column label="操作" width="180">
        <template slot-scope="scope">
          <el-button v-if="scope.row.status === 0" type="primary" @click="enterRefuse(scope.row.id, 1)">
            同意
          </el-button>
          <el-button v-if="scope.row.status === 0" type="danger" @click="enterRefuse(scope.row.id, 2)">
            拒绝
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      background
      @current-change="handlePageChange"
      :current-page="query.pageNum"
      :page-size="query.pageSize"
      layout="total, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>
  </div>
</template>
<script>
import { szxRecordList } from "@/api/ds/newSystem";
import { reviewGarageWithdrawal } from "@/api/ds/garage";
export default {
  components: {},
  props: {},
  data() {
    return {
      query: {
        type: "车房券提现审核中",
        pageNum: 1,
        pageSize: 10,
      },
      list: [],
      total: 0,
    };
  },
  computed: {},
  watch: {},
  created() {
    this.getData();
  },
  methods: {
    handlePageChange(value) {
      this.query.pageNum = value;
      this.getData();
    },

    async getData() {
      let res = await szxRecordList(this.query);
      if (res.code === 200) {
        this.list = res.rows;
        this.total = res.total;
      }
    },

    async enterRefuse(id, enter) {
      console.log(id);
      console.log(enter);

      if (enter === 2) {
        this.$prompt("请输入拒绝原因", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
        })
          .then(async ({ value }) => {
            let res = await reviewGarageWithdrawal({
              remark: value,
              type: enter,
              recordId: id,
            });

            if (res.code === 200) {
              console.log(res);
              this.getData();
              this.$notify({
                type: "success",
                message: res.msg,
              });
            }
          })
          .catch(() => {
            this.$message({
              type: "info",
              message: "取消输入",
            });
          });
      } else {
        let res = await reviewGarageWithdrawal({
          remark: "",
          type: enter,
          recordId: id,
        });

        if (res.code === 200) {
          console.log(res);
          this.getData();
          this.$notify({
            type: "success",
            message: res.msg,
          });
        }
      }
    },
  },
  mounted() {},
  beforeCreate() {},
  beforeMount() {},
  beforeUpdate() {},
  updated() {},
  beforeDestroy() {},
  destroyed() {},
  activated() {},
  deactivated() {},
};
</script>
<style lang="scss" scoped>
.page {
  padding: 20px;
}
</style>
